package com.ys.erp.stage_user_service.utils;

import com.junziqian.sdk.bean.ResultInfo;
import com.junziqian.sdk.bean.req.sign.ApplySignReq;
import com.junziqian.sdk.util.RequestUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lwj
 * @date 2025/8/14
 */
@Service
@Slf4j
@RefreshScope
@RequiredArgsConstructor
public class JzqUtil {

    private final RequestUtils jzqRequestUtils;

    @Value("${jzq.preview-contract-url}")
    private String previewContractUrl;


    /**
     * 预览合同
     *
     * @param applyNo               jzq合同编号
     * @return                      预览连接
     */
    public String previewContract(String applyNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("applyNo", applyNo);
        ResultInfo<String> res = jzqRequestUtils.doPost(previewContractUrl, params);
        log.info(res.toString());
        return res.getData();
    }

    //下载
    public String getContractDownloadUrl(String applyNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("applyNo", applyNo);
        ResultInfo<String> ri = jzqRequestUtils.doPost("/v2/sign/linkFile", params);
        return ri.getData();
    }


    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class GetReqParams extends ApplySignReq {
        private String notifyUrl;
    }

}
